package com.servlet;


import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Transaction;

import com.hibernate.dao.HibernateSessionFactory;
import com.hibernate.model.Basicinfo;
import com.hibernate.model.BasicinfoDAO;



public class Login extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Constructor of the object.
	 */
	public Login() {
		super();
	}
	protected void service(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
	
		 String verity=(String)request.getAttribute("verity");		 
		 String password=(String)request.getAttribute("password");
		 String userid=request.getParameter("userid");
		 String unread=(String)request.getAttribute("unread");
		String status=(String) request.getAttribute("status");
		String logined=(String)request.getAttribute("logined");
		// System.out.println(unrd.getName()+" "+unrd.getValue()+" "+unread+userid);
		response.reset();
		response.setContentType("text/json");	
		
	 if(password!=null)	
		if(password.equals("yes"))
		{
		   request.getSession().setAttribute("userid", userid);
		    
		   Cookie unrd=new Cookie("unread",unread);
		   unrd.setMaxAge(-1);
		   unrd.setPath("/stusys");
		   
		   Cookie st=new Cookie("status",status);
		   st.setMaxAge(-1);
		   st.setPath("/stusys");
		   
		   response.addCookie(unrd);
		//  response.addCookie(usid);
		   response.addCookie(st);
		   
		}
	
	    PrintWriter out = response.getWriter();	    	
	    out.println("{\"verity\":\""+verity+"\",\"password\" : \""+password+"\",\"userid\":\""+userid+"\",\"unread\":\""+unread+"\",\"logined\":\""+logined+"\"}");
	    out.flush();
	    out.close();
		
	}

}
